<?php
class Zendvn_View_Helper_CmsShareButton extends Zend_View_Helper_Abstract{
	
	//$this->formRadio($name,$value,$attribs,$options, $listep);
	/*$attribs = array(
					'icon'=>'icon-32-delete.png',
					'iconDir'=>'images/toolbar/',
				)*/
	//$options = array('type'=>'submit','name'=>'appForm');
	public function cmsShareButton($name,$arrParam = null, $attribs = null,$options = null ){
		
		$arrParam['class'] = empty($arrParam['class'])?'addthis_button':'addthis_button ' . $arrParam['class'];
		
		$xhtml = '<a class="' . $arrParam['class'] . '"
					href="http://www.addthis.com/bookmark.php?v=250&amp;pubid=xa-4fd86e00530bf704">
					'. $name .'
				</a>
				<script type="text/javascript" 
						src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4fd86e00530bf704">
				</script>';
				
		return $xhtml;
	}
	
	public function meShare($url, $title = null, $description = null, $options = null){
		$xhtml = '<a rel="nofollow" id="zing_me" target="_blank" href="#" onclick="window.open(\'http://link.apps.zing.vn/share?u=' . $url . '\', \'mywindow\',\'width=700,height=500\')">
						<img src="' . TEMPLATE_URL .'/public/default/images/icon-zing.gif" title="Chia sẻ trên Zing" alt="Facebook" class="sociable-hovers tipTip">
					</a>';
		
		
		
		return $xhtml;
	}
	
	public function facebookLike($url, $title = null, $description = null, $options = null){
		$xhtml = '<a rel="nofollow" id="facebook" target="_blank" href="#" onclick="window.open(\'http://www.facebook.com/sharer/sharer.php?u=' . $url . '\', \'mywindow\',\'width=700,height=500\')">
						<img src="' . TEMPLATE_URL .'/public/default/images/icon-facebook.png" title="Chia sẻ trên Facebook" alt="Facebook" class="sociable-hovers tipTip" />
					</a>';
		
		
		
		return $xhtml;
	}
	
	public function twitterShare($url, $title = null, $description = null, $options = null){
		$description = str_replace("'", "\'", $description);
		$title = str_replace("'", "\'", $title);
		
		$xhtml = '<a rel="nofollow" id="twitter" target="_blank" 
					href="#"
					onclick="window.open(\'https://twitter.com/intent/tweet?source=webclient&amp;text=' . $description . ' - ' . $title . ' - ' . $url . '\',
								\'\',\'width=600,height=400,left=0px,scrollbars=no\')" 
					onfocus="this.blur();">
					<img src="' . TEMPLATE_URL .'/public/default/images/icon-twitter.png" title="Chia sẻ trên Twitter" alt="Twitter" class="sociable-hovers tipTip">
				</a>';
		return $xhtml;
	}
	
	public function googlePlus($url, $title = null, $description = null, $options = null){
		$xhtml = '<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>';
		$xhtml .= '<div 
						class="g-plusone" 
						data-size="small" 
						data-href="' . $url . '"
						data-annotation="none"></div>';		
		return $xhtml;
	}
	
	public function linkedIn($url, $title = null, $description = null, $options = null){
		$xhtml = '<a 
					onclick="window.open(\'http://www.linkedin.com/shareArticle?mini=true&url=' . $url . '\',
								\'\',\'width=600,height=400,left=0px,scrollbars=no\')" href="javascript:void(0)"> 
					<img src="' . TEMPLATE_URL .'/public/default/images/icon-linkin.png" 
						alt="Chia sẻ trên LinkedIn" 
						height="16"
						title="Chia sẻ trên LinkedIn" class="tipTip" />
				</a>';
		return $xhtml;
	}
	
	public function printButton($url){
		$xhtml = '<a href="#" onclick="window.print()">
					<img src="' . TEMPLATE_URL .'/public/default/images/icon-print.gif"
						alt="Print page" 
						height="16" 
						title="Print page" />
					</a>';
		return $xhtml;
	}
	
	public function emailButton($url){
		$info = new Zendvn_System_Info();
		$infoId = $info->getMemberInfo('id');
		$cmsUrl 	= new Zendvn_View_Helper_CmsUrl();
		$linkEmail 	= $cmsUrl->cmsUrl(array(
										'module' => 'user',
										'controller' => 'index',
										'action' => 'email-share',
										'url' => base64_encode($url)
										));
		
		if($infoId == 2){
			$xhtml = '<a href="javascript:;" class="request-register">
							<img src="' . TEMPLATE_URL .'/public/default/images/icon-email.png"
								alt="Print page"
								height="16"
								title="Print page" />
						</a>';
		}else{
			$xhtml = '<a href="' . $linkEmail . '" onclick="return fancyBox(this)">
						<img src="' . TEMPLATE_URL .'/public/default/images/icon-email.png"
							alt="Print page" 
							height="16" 
							title="Print page" />
						</a>';
		}
		return $xhtml;
	}
	
	public function socialButton($url, $options = null){
		$whiteSpace = '';
		
		$title 			= !empty($options['title'])?$options['title']:'Maxx99';
		$description 	= !empty($options['description'])?$options['description']:'Maxx99';
		
		$description 	= preg_replace('#\s+#imsU', ' ', $description);
		
		
		
		if($options['print'] == true || empty($options['print'])){
//			$xhtml = self::printButton($url) . $whiteSpace;
		}
		
		if($options['email'] == true || empty($options['email'])){
//			$xhtml .= self::emailButton($url) . $whiteSpace;
		}
		if($options['zing_me'] == true || empty($options['zing_me'])){
			$xhtml .= self::meShare($url, $title, $description) . $whiteSpace;
		}
		if($options['facebook'] == true || empty($options['facebook'])){
			$xhtml .= self::facebookLike($url, $title, $description) . $whiteSpace;
		}
		if($options['twitter'] == true || empty($options['twitter'])){
			$xhtml .= self::twitterShare($url, $title, $description) . $whiteSpace;
		}
		if($options['google'] == true || empty($options['google'])){
			$xhtml .= self::googlePlus($url, $title, $description) . $whiteSpace;
		}
		if($options['linkedin'] == true || empty($options['linkedin'])){
			$xhtml .= self::linkedIn($url, $title, $description) . $whiteSpace;
		}
		
		return $xhtml;
	}
	
	
	
	
	
	
	
	
	
	
}